<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Document</title>
</head>
<body>
    <script>
        //reduce
        //reduce((previous()，current,index,arr),上一个返回值)
        let arr = [1,2,5,2,3,5]
    //    const result= arr.reduce((previous,current) => {
    //         return previous+current
    //     })
    //     console.log(result)

    //     const result1 = arr.reduce((previous,current) => {
    //         return previous +current
    //     },100)
    //

    //实现去重
        const result = arr.reduce((previous,current) => {
            if(previous.indexOf(current) === -1){
                previous.push(current)
            }
            return previous
        },[])
        console.log(result)

        //数组扁平化操作  flat（默认为1 或infinity）
        let arr1 = [1,2,3,[2,3,[4,6]]]
        console.log(arr1.flat())  //默认一层
        console.log(arr1.flat(Infinity))  //全部扁平化
    </script>
</body>
</html>